import { Controller, Get, Query } from '@nestjs/common';
import { Users } from '@entities/Users';
import { InjectEntityManager, InjectMikroORM } from '@mikro-orm/nestjs';
import { EntityManager, MikroORM } from '@mikro-orm/mysql';
import { JsonApiResponse } from '@utils/json.api.response';
import { ChatRooms } from '@entities/ChatRooms';

@Controller('chat')
export class ChatController {
    constructor(
        @InjectMikroORM('zp')
        private readonly orm : MikroORM,
        @InjectEntityManager('zp')
        private readonly em : EntityManager 
    ){

    }

    @Get('rooms')
    async rooms(@Query('userId') userId){
        const user = await this.em.findOne(Users,{id:userId},{populate:['roomsAsChatRoomMembers']});

        //const rooms = await this.em.find(ChatRooms,{creator:{$eq:'1'}})

        return JsonApiResponse.new(user.roomsAsChatRoomMembers)
    }
}
